/*
 *  $Id: Abstract.cs 975 2009-12-16 17:13:22Z thenn.erannor $
 *  This file is a part of Ragima CCG.
 *  (C) 2008 Ragima development group.
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System.Collections.Generic;

namespace Ragima {
    /// <summary>
    /// Абстрактное условие (конкретные условия должны давать его наследники)
    /// </summary>
    public abstract class Condition {
        /// <summary>
        /// Проверка, допустимо ли это условие
        /// </summary>
        public abstract bool Test(AbstractObject caster, Card card);
        /// <summary>
        /// Действие условия
        /// </summary>
        public virtual void DoCondition(AbstractObject caster, Card card) {}
        /// <value>
        /// Фраза сообщения при неудачной проверке условия
        /// </value>
        public abstract Languages.Phrase Notice { get; }
        /// <value>
        /// Строка сообщения при неудачной проверке условия
        /// </value>
        public virtual string NoticeText {
            get {
                Languages.Phrase notice = Notice;
                return notice != null ? notice.GetText() : string.Empty;
            }
        }
        /// <summary>
        /// Запрос веса условия
        /// </summary>
        public virtual int GetWeight(Card card) {
            return 0;
        }

        /// <summary>
        /// Проверить все условия
        /// </summary>
        public static bool TestAll(IEnumerable<Condition> conditions, AbstractObject caster, Card card, bool notice) {
            foreach (Condition condition in conditions) {
                if (!condition.Test(caster, card)) {
                    if (notice) caster.Owner.Game.ErrorNotice(condition.NoticeText);
                    return false;
                }
            }
            return true;
        }

        /// <summary>
        /// Выполнить все условия.
        /// </summary>
        public static void DoConditionAll(IEnumerable<Condition> conditions, AbstractObject caster, Card card) {
            foreach (Condition condition in conditions)
                condition.DoCondition(caster, card);
        }
    }
}
